/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * MjChatFrame.java
 *
 * Created on 7-nov-2009, 21.42.29
 */
package Messenj;

import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.sound.sampled.LineUnavailableException;
import javax.sound.sampled.UnsupportedAudioFileException;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;
import net.sf.jml.MsnContact;

/**
 *
 * @author edoardo
 */
public class MjChatFrame extends javax.swing.JFrame {

    HtmlConverter html;

    /** Creates new form MjChatFrame */
    public MjChatFrame() {
        initComponents();
        this.setSize(400, this.getHeight());
        html = new HtmlConverter();
        this.jEditorPane1.setContentType("text/html");
    }

    public void isTyping() {
    }

    public void contactJoined(MsnContact mc) {
    }

    public void contacLeave(MsnContact mc) {
    }

    public void nudgeReceived() {
        int startx = this.getLocationOnScreen().x;
        int starty = this.getLocationOnScreen().y;
        boolean dir = true;
        try {
            new Player("beep3");
        } catch (LineUnavailableException ex) {
            Logger.getLogger(MjChatFrame.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IOException ex) {
            Logger.getLogger(MjChatFrame.class.getName()).log(Level.SEVERE, null, ex);
        } catch (UnsupportedAudioFileException ex) {
            Logger.getLogger(MjChatFrame.class.getName()).log(Level.SEVERE, null, ex);
        }
        for (int i = 0; i < 50; i++) {
            if (dir) {
                if (i > 0) {
                    startx += 6;
                    starty += 6;
                } else {
                    startx += 3;
                    starty += 3;
                }
                this.setLocation(startx, starty);
            } else {
                startx -= 6;
                starty -= 6;
                this.setLocation(startx, starty);
            }
            dir = !dir;
            try {
                Thread.sleep(60);
            } catch (InterruptedException ex) {
                Logger.getLogger(MjChatFrame.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
        this.requestFocus();
    }

    public void add(String mex) {
        String s = this.jEditorPane1.getText();
        this.jEditorPane1.setText(s + mex + "<br>");
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jSplitPane1 = new javax.swing.JSplitPane();
        jPanel1 = new javax.swing.JPanel();
        jScrollPane2 = new javax.swing.JScrollPane();
        jList1 = new javax.swing.JList();
        jPanel2 = new javax.swing.JPanel();
        jSplitPane2 = new javax.swing.JSplitPane();
        jPanel3 = new javax.swing.JPanel();
        jTextField1 = new javax.swing.JTextField();
        jButton1 = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        jEditorPane1 = new javax.swing.JEditorPane();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setMinimumSize(new java.awt.Dimension(178, 200));
        getContentPane().setLayout(new java.awt.GridLayout(1, 0));

        jSplitPane1.setDividerLocation(300);

        jPanel1.setLayout(new java.awt.GridLayout());

        jScrollPane2.setViewportView(jList1);

        jPanel1.add(jScrollPane2);

        jSplitPane1.setRightComponent(jPanel1);

        jPanel2.setLayout(new java.awt.GridLayout(1, 0));

        jSplitPane2.setDividerLocation(261);
        jSplitPane2.setOrientation(javax.swing.JSplitPane.VERTICAL_SPLIT);

        jPanel3.setLayout(new java.awt.GridLayout(1, 0));
        jPanel3.add(jTextField1);

        jButton1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Resources/Images/invia.gif"))); // NOI18N
        jButton1.setPreferredSize(new java.awt.Dimension(27, 27));
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });
        jPanel3.add(jButton1);

        jSplitPane2.setBottomComponent(jPanel3);

        jEditorPane1.setBackground(java.awt.Color.white);
        jEditorPane1.setContentType("text/html");
        jEditorPane1.setText("<html>\n  <head>\n\n  </head>\n  <body>\n    <p style=\"margin-top: 0\">\n\n    </p>\n  </body>\n</html>\n");
        jScrollPane1.setViewportView(jEditorPane1);

        jSplitPane2.setLeftComponent(jScrollPane1);

        jPanel2.add(jSplitPane2);

        jSplitPane1.setLeftComponent(jPanel2);

        getContentPane().add(jSplitPane1);

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        // TODO add your handling code here:
        ThreadNotificator tn = new ThreadNotificator("Ciao mondo");
        tn.start();
        this.nudgeReceived();
    }//GEN-LAST:event_jButton1ActionPerformed

    /**
     * @param args the command line arguments++
     */
    public static void main(String args[]) {
                new MjChatFrame().setVisible(true);
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1;
    private javax.swing.JEditorPane jEditorPane1;
    private javax.swing.JList jList1;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JSplitPane jSplitPane1;
    private javax.swing.JSplitPane jSplitPane2;
    private javax.swing.JTextField jTextField1;
    // End of variables declaration//GEN-END:variables
}
